package com.example.arithmeticleetcode.util;

import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-08-05 14:33
 **/
public class TimeTool {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");

    public interface Task {
        void execute();
    }

    public static void check(String title, Task task) {
        if (Objects.isNull(task)) return;

        title = Objects.isNull(title) ? "" : ("【" + title + "】");
        System.out.println(title);
        System.out.println("开始：" + sdf.format(new Date()));
        long begin = System.currentTimeMillis();
        task.execute();
        long end = System.currentTimeMillis();
        System.out.println("结束：" + System.currentTimeMillis());
        double delte = (end - begin) / 1000.0;
        System.out.println("耗时：" + delte + "秒");
        System.out.println("===========================================");
    }
}
